package com.example.pipline.yu.senior.handler;

import cn.hutool.core.map.MapUtil;
import com.example.pipline.yu.senior.context.InstanceBuildContext;
import io.micrometer.common.util.StringUtils;
import org.springframework.stereotype.Component;

import java.util.Map;


@Component
public class InputDataPreCheckerHandler implements ContextHandler<InstanceBuildContext> {


    @Override
    public boolean handle(InstanceBuildContext context) {

        Map<String, Object> formInput = context.getFormInput();

        if (MapUtil.isEmpty(formInput)) {
            context.setErrorMsg("表单输入数据不能为空");
            return false;
        }

        String instanceName = (String) formInput.get("instanceName");

        if (StringUtils.isBlank(instanceName)) {
            context.setErrorMsg("表单输入数据必须包含实例名称");
            return false;
        }

        return true;
    }
}